// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import common from './common/common.js'
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import ajax from 'axios'
import App from './App'
import router from './router'
import './assets/style/base.css'


Vue.config.productionTip = false

Vue.use(ElementUI);

Vue.use(router);

Vue.prototype.common = common;



router.beforeEach((to, from, next) => {

//   if (to.path == '/login') {

//     localStorage.removeItem('token');

//   }

  var user = localStorage.getItem('token');

  //if (!user && to.path != '/login') {

    //  next({

      //    path: '/login'

      //});

  //} else {

    //  next();

  ///}
  next();
});

var token = function( token ){
   
    if( token !== undefined ){

        return localStorage.setItem('token',token);


    }else if(token == 'delete'){

        return localStorage.removeItem(token);

    }
   
    return localStorage.getItem('token');
}


Vue.prototype.token = token;

var axiosConfig = {

    baseURL: 'http://39.109.123.30/work/club/inside_club_manager_soft/public/',

    timeout: 3000,

    headers:{

        token:'',

        'Content-Type' : 'application/json;charset=utf-8'

        }

};

var ajaxInstance =  ajax.create(axiosConfig);

ajaxInstance.interceptors.request.use(function(res){
  
    var url = res.url;

    if( url !== '"auth/login"' ){

        res.headers.token = token();

    }

    return res;

});

//响应式拦截器
ajaxInstance.interceptors.response.use(function(res){

    var response = res.data;

    if( response.code == 401 ){

        

    }

    return res;
});

Vue.prototype.apipath = ajaxInstance;

new Vue({
  el: '#app',
  router,
  components: { App },
  render: h => h(App),
})
